<?php

namespace TaoJiang\Teacher\Tests\Unit\Domain\Model;

/***************************************************************
 *  Copyright notice
 *
 *  (c) 2017 
 *
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/

/**
 * Test case for class \TaoJiang\Teacher\Domain\Model\Teacher.
 *
 * @copyright Copyright belongs to the respective authors
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
 *
 */
class TeacherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
{
	/**
	 * @var \TaoJiang\Teacher\Domain\Model\Teacher
	 */
	protected $subject = NULL;

	public function setUp()
	{
		$this->subject = new \TaoJiang\Teacher\Domain\Model\Teacher();
	}

	public function tearDown()
	{
		unset($this->subject);
	}

	/**
	 * @test
	 */
	public function getNameReturnsInitialValueForString()
	{
		$this->assertSame(
			'',
			$this->subject->getName()
		);
	}

	/**
	 * @test
	 */
	public function setNameForStringSetsName()
	{
		$this->subject->setName('Conceived at T3CON10');

		$this->assertAttributeEquals(
			'Conceived at T3CON10',
			'name',
			$this->subject
		);
	}

	/**
	 * @test
	 */
	public function getTohomeReturnsInitialValueForBool()
	{
		$this->assertSame(
			FALSE,
			$this->subject->getTohome()
		);
	}

	/**
	 * @test
	 */
	public function setTohomeForBoolSetsTohome()
	{
		$this->subject->setTohome(TRUE);

		$this->assertAttributeEquals(
			TRUE,
			'tohome',
			$this->subject
		);
	}

	/**
	 * @test
	 */
	public function getIsworkReturnsInitialValueForBool()
	{
		$this->assertSame(
			FALSE,
			$this->subject->getIswork()
		);
	}

	/**
	 * @test
	 */
	public function setIsworkForBoolSetsIswork()
	{
		$this->subject->setIswork(TRUE);

		$this->assertAttributeEquals(
			TRUE,
			'iswork',
			$this->subject
		);
	}

	/**
	 * @test
	 */
	public function getPositionReturnsInitialValueForString()
	{
		$this->assertSame(
			'',
			$this->subject->getPosition()
		);
	}

	/**
	 * @test
	 */
	public function setPositionForStringSetsPosition()
	{
		$this->subject->setPosition('Conceived at T3CON10');

		$this->assertAttributeEquals(
			'Conceived at T3CON10',
			'position',
			$this->subject
		);
	}

	/**
	 * @test
	 */
	public function getProfileReturnsInitialValueForFileReference()
	{
		$this->assertEquals(
			NULL,
			$this->subject->getProfile()
		);
	}

	/**
	 * @test
	 */
	public function setProfileForFileReferenceSetsProfile()
	{
		$fileReferenceFixture = new \TYPO3\CMS\Extbase\Domain\Model\FileReference();
		$this->subject->setProfile($fileReferenceFixture);

		$this->assertAttributeEquals(
			$fileReferenceFixture,
			'profile',
			$this->subject
		);
	}

	/**
	 * @test
	 */
	public function getShortReturnsInitialValueForString()
	{
		$this->assertSame(
			'',
			$this->subject->getShort()
		);
	}

	/**
	 * @test
	 */
	public function setShortForStringSetsShort()
	{
		$this->subject->setShort('Conceived at T3CON10');

		$this->assertAttributeEquals(
			'Conceived at T3CON10',
			'short',
			$this->subject
		);
	}

	/**
	 * @test
	 */
	public function getContactReturnsInitialValueForString()
	{
		$this->assertSame(
			'',
			$this->subject->getContact()
		);
	}

	/**
	 * @test
	 */
	public function setContactForStringSetsContact()
	{
		$this->subject->setContact('Conceived at T3CON10');

		$this->assertAttributeEquals(
			'Conceived at T3CON10',
			'contact',
			$this->subject
		);
	}

	/**
	 * @test
	 */
	public function getWorksReturnsInitialValueForString()
	{
		$this->assertSame(
			'',
			$this->subject->getWorks()
		);
	}

	/**
	 * @test
	 */
	public function setWorksForStringSetsWorks()
	{
		$this->subject->setWorks('Conceived at T3CON10');

		$this->assertAttributeEquals(
			'Conceived at T3CON10',
			'works',
			$this->subject
		);
	}

	/**
	 * @test
	 */
	public function getPaperReturnsInitialValueForString()
	{
		$this->assertSame(
			'',
			$this->subject->getPaper()
		);
	}

	/**
	 * @test
	 */
	public function setPaperForStringSetsPaper()
	{
		$this->subject->setPaper('Conceived at T3CON10');

		$this->assertAttributeEquals(
			'Conceived at T3CON10',
			'paper',
			$this->subject
		);
	}

	/**
	 * @test
	 */
	public function getProfessionReturnsInitialValueForString()
	{
		$this->assertSame(
			'',
			$this->subject->getProfession()
		);
	}

	/**
	 * @test
	 */
	public function setProfessionForStringSetsProfession()
	{
		$this->subject->setProfession('Conceived at T3CON10');

		$this->assertAttributeEquals(
			'Conceived at T3CON10',
			'profession',
			$this->subject
		);
	}

	/**
	 * @test
	 */
	public function getCourseReturnsInitialValueForString()
	{
		$this->assertSame(
			'',
			$this->subject->getCourse()
		);
	}

	/**
	 * @test
	 */
	public function setCourseForStringSetsCourse()
	{
		$this->subject->setCourse('Conceived at T3CON10');

		$this->assertAttributeEquals(
			'Conceived at T3CON10',
			'course',
			$this->subject
		);
	}

	/**
	 * @test
	 */
	public function getProjectsReturnsInitialValueForString()
	{
		$this->assertSame(
			'',
			$this->subject->getProjects()
		);
	}

	/**
	 * @test
	 */
	public function setProjectsForStringSetsProjects()
	{
		$this->subject->setProjects('Conceived at T3CON10');

		$this->assertAttributeEquals(
			'Conceived at T3CON10',
			'projects',
			$this->subject
		);
	}

	/**
	 * @test
	 */
	public function getRewardReturnsInitialValueForString()
	{
		$this->assertSame(
			'',
			$this->subject->getReward()
		);
	}

	/**
	 * @test
	 */
	public function setRewardForStringSetsReward()
	{
		$this->subject->setReward('Conceived at T3CON10');

		$this->assertAttributeEquals(
			'Conceived at T3CON10',
			'reward',
			$this->subject
		);
	}

	/**
	 * @test
	 */
	public function getDepartmentReturnsInitialValueForDepartment()
	{
		$newObjectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
		$this->assertEquals(
			$newObjectStorage,
			$this->subject->getDepartment()
		);
	}

	/**
	 * @test
	 */
	public function setDepartmentForObjectStorageContainingDepartmentSetsDepartment()
	{
		$department = new \TaoJiang\Teacher\Domain\Model\Department();
		$objectStorageHoldingExactlyOneDepartment = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
		$objectStorageHoldingExactlyOneDepartment->attach($department);
		$this->subject->setDepartment($objectStorageHoldingExactlyOneDepartment);

		$this->assertAttributeEquals(
			$objectStorageHoldingExactlyOneDepartment,
			'department',
			$this->subject
		);
	}

	/**
	 * @test
	 */
	public function addDepartmentToObjectStorageHoldingDepartment()
	{
		$department = new \TaoJiang\Teacher\Domain\Model\Department();
		$departmentObjectStorageMock = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage', array('attach'), array(), '', FALSE);
		$departmentObjectStorageMock->expects($this->once())->method('attach')->with($this->equalTo($department));
		$this->inject($this->subject, 'department', $departmentObjectStorageMock);

		$this->subject->addDepartment($department);
	}

	/**
	 * @test
	 */
	public function removeDepartmentFromObjectStorageHoldingDepartment()
	{
		$department = new \TaoJiang\Teacher\Domain\Model\Department();
		$departmentObjectStorageMock = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage', array('detach'), array(), '', FALSE);
		$departmentObjectStorageMock->expects($this->once())->method('detach')->with($this->equalTo($department));
		$this->inject($this->subject, 'department', $departmentObjectStorageMock);

		$this->subject->removeDepartment($department);

	}
}
